<!DOCTYPE html>
<html lang="en">
<head>
   <meta charset="UTF-8">
   <meta name="viewport" content="width=device-width, initial-scale=1.0">
   <meta http-equiv="X-UA-Compatible" content="ie=edge">
   <title>Document</title>
</head>
<body>
   <script>
      var arr1 = [1, 2, 2, 3, 4, 5];
      var arr2 = [2, 2, 3, 4, , 6, 7, 8];
      // 创建函数
      var res = arr1.filter(function(value,index){
         // 筛选出arr1跟arr2共有的元素
         return (arr2.indexOf(value) !== -1)
      })
      // console.log(res); //[2,2,3,4]
      // 去重
      var res1 = res.reduce(function(prev,value){
         // 将prev定义为数组，res里面的value值在prve里面查找，没有就添加进prve,有就跳过
         return (prev.indexOf(value) === -1) ? prev.concat(value) : prev;  
      },[])
      console.log(res1);
   </script>
</body>
</html>